/************************************************************
https://anotherssisframework.codeplex.com

Copyright (c) 2014, Allen J. Zyck <sql.architect@outlook.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


************************************************************/

/***********
File: DWStagingDummyStagingObjects.sql

Description:
This is a SQL script template creates the dummy database objects
in the staging database. These are only required in development.
Creating them prevents the package templates from kicking off errors.

***********/

USE <database, sysname, DWStaging>
GO

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'busunit')
BEGIN
	EXEC('CREATE SCHEMA [busunit] AUTHORIZATION [dbo]');
END
GO

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'common')
BEGIN
	EXEC('CREATE SCHEMA [common] AUTHORIZATION [dbo]');
END
GO

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'hist')
BEGIN
	EXEC('CREATE SCHEMA [hist] AUTHORIZATION [dbo]');
END
GO

IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'stg')
BEGIN
	EXEC('CREATE SCHEMA [stg] AUTHORIZATION [dbo]');
END
GO


CREATE PROCEDURE stg.LoadDummyTypeIIDim as
BEGIN
	-- Fact or Dim here...
	SELECT CAST(1 as INT) as StageKey, CAST('cccc' as varchar(10)) as Field1, CAST('dddd' as varchar(10)) as Field2, CAST('/110' AS varchar(128)) as LineageString;
	
END
GO

CREATE PROCEDURE stg.LoadDummyTypeIDim as
BEGIN
	-- Fact or Dim here...
	SELECT CAST(1 as INT) as StageKey, CAST('aaaa' as varchar(10)) as Field1, CAST('bbc' as varchar(10)) as Field2, CAST('/110' AS varchar(128)) as LineageString;
	
END
GO

CREATE PROCEDURE stg.LoadDummyFact as
BEGIN
	SELECT CAST(1 as INT) as StageKey, CAST(1 as INT) as Dim1Key, CAST(1 as INT) as Dim2Key, CAST(10 as INT) as Measure, CAST('/100' AS varchar(128)) as LineageString;
END
GO 

CREATE TABLE stg.DummyTypeIIError(
	RowNumber int NULL,
	ErrorNumber int NULL,
	ErrorDescription varchar(256) NULL,
	ColumnId int NULL,
	LineageTMST datetime NULL,
	LineageString varchar(128) NULL,
	InsertTMST datetime NOT NULL,
	InsertedBy sysname NOT NULL
) ON "default"
GO

CREATE TABLE stg.DummyTypeIError(
	RowNumber int NULL,
	ErrorNumber int NULL,
	ErrorDescription varchar(256) NULL,
	ColumnId int NULL,
	LineageTMST datetime NULL,
	LineageString varchar(128) NULL,
	InsertTMST datetime NOT NULL,
	InsertedBy sysname NOT NULL
) ON "default"
GO

CREATE TABLE stg.DummyStagingTable(
	StagingKey int IDENTITY(1,1) NOT NULL CONSTRAINT PK_DummyStagingTable PRIMARY KEY CLUSTERED,
	DummyConstant int NULL,
	LineageTMST datetime NULL,
	LineageString varchar(128) NULL,
 ) ON "default"
GO

CREATE TABLE hist.DummyHistoryTable(
	DummyHistoryKey int IDENTITY(1,1) NOT NULL,
	DummyConstant int NULL,
	LineageTMST datetime NULL,
	LineageString varchar(128) NULL
) ON "default"
GO

CREATE TABLE stg.DummyFactError(
	RowNumber int NULL,
	ErrorNumber int NULL,
	ErrorDescription varchar(256) NULL,
	ColumnId int NULL,
	LineageTMST datetime NULL,
	LineageString varchar(128) NULL,
	InsertTMST datetime NOT NULL,
	InsertedBy sysname NOT NULL
) ON "default"
GO

ALTER TABLE stg.DummyFactError ADD  CONSTRAINT DF_stg_DummyFactError_InsertTMST  DEFAULT (getdate()) FOR InsertTMST
GO

ALTER TABLE stg.DummyFactError ADD  CONSTRAINT DF_stg_DummyFactError_InsertedBy  DEFAULT (suser_sname()) FOR InsertedBy
GO

ALTER TABLE stg.DummyTypeIError ADD  CONSTRAINT DF_stg_DummyTypeIError_InsertTMST  DEFAULT (getdate()) FOR InsertTMST
GO

ALTER TABLE stg.DummyTypeIError ADD  CONSTRAINT DF_stg_DummyTypeIError_InsertedBy  DEFAULT (suser_sname()) FOR InsertedBy
GO

ALTER TABLE stg.DummyTypeIIError ADD  CONSTRAINT DF_stg_DummyTypeIIError_InsertTMST  DEFAULT (getdate()) FOR InsertTMST
GO

ALTER TABLE stg.DummyTypeIIError ADD  CONSTRAINT DF_stg_DummyTypeIIError_InsertedBy  DEFAULT (suser_sname()) FOR InsertedBy
GO
